<meta charset="UTF-8" />
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <link rel="stylesheet" href="/layui/css/layui.css"/>

</head>
<style type="text/css">
    .myData .layui-form-item{
        margin: 20px 100px 10px 45px;
    }
    .myData .layui-form-label{
        width: 85px;
    }
    .layui-input-block {
        margin-left: 120px;
    }
</style>
<div class="layui-form">
<form class="layui-form myData"  id="saveForm" action="" method="post" lay-filter="stuform">
 
    <div class="layui-form-item">
        <label class="layui-form-label">上级部门：</label>
        <div class="layui-input-block">
            <input type="text"  id="tree" lay-filter="tree" class="layui-input" />
            <input hidden="true" id="menuPid" name="pid" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称：</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required"  class="layui-input" />
        </div>
    </div>
     <div class="layui-form-item" >
        <label class="layui-form-label">资源路径：</label>
        <div class="layui-input-block">
            <input type="text" name="url"  class="layui-input" />
        </div>
    </div>
   <div class="layui-form-item">
            <label class="layui-form-label" style="width:100px">是否前台按钮：</label>
            <div class="layui-input-block" id="IsPurchased" >
                <input type="radio"  name="ismenu" value="1" title="是" lay-filter="aaa" />
                <input type="radio"  name="ismenu" value="0" title="否" lay-filter="aaa" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:100px">是否启用菜单：</label>
            <div class="layui-input-block" id="IsPurchased" >
                <input type="radio"  name="del_flag" value="1" title="是" lay-filter="del_flag" />
                <input type="radio"  name="del_flag" value="0" title="否" lay-filter="del_flag" />
            </div>
        </div>
       <!--   <div class="layui-form-item">
            <label class="layui-form-label" style="width:100px">是否默认菜单：</label>
            <div class="layui-input-block" id="IsPurchased" >
                <input type="radio"  name="issys" value="1" title="是" lay-filter="aaa" />
                <input type="radio"  name="issys" value="0" title="否" lay-filter="aaa" />
            </div>
        </div> -->
      
  <!--  <div class="layui-form-item" >
        <label class="layui-form-label">编号：</label>
        <div class="layui-input-block">
            <input type="text" name="number" th:value="${model.number}" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">排序：</label>
        <div class="layui-input-block">
            <input type="text" name="idx" value="0" th:value="${model.idx}" class="layui-input" />
        </div>
    </div> -->
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
                 <button type="button" onclick="save()" class="layui-btn" >立即提交</button>

        </div>
    </div> 
</form>
</div>
 <script type="text/javascript" src="/layui/layui.all.js"></script>
  <script type="text/javascript" src="/layui/layui.js"></script>
 
<script type="text/javascript" src="/js/jquery/jquery-3.3.1.min.js"></script>
<script th:inline="javascript">

     layui.config({
        base: '/layui/'
    }).extend({
        treetable: 'treeSelect'
    }).use(["treeSelect", "form", "tree"], function () {
        var form = layui.form;
        var tree = layui.tree;
        form.render('select');
        var treeSelect = layui.treeSelect;
        treeSelect.render({
            // 选择器
            elem: '#tree',
            // 数据
            data: '/menu/treeSelect/',
            // 异步加载方式：get/post，默认get
            type: 'get',
            // 占位符
            placeholder: '上级菜单',
            // 是否开启搜索功能：true/false，默认false
            search: true,
            showCheckbox: true,     //是否显示复选框
            
            // 一些可定制的样式
            style: {
                folder: {
                    enable: true
                },
                line: {
                    enable: true
                }
            },
             click: function(d){
                console.log(d.current.id);
                 $("#menuPid").attr("value",d.current.id);
            },
            // 加载完成后的回调函数
            success: function (d) {
            
            
//                获取zTree对象，可以调用zTree方法
                var treeObj = treeSelect.zTree('tree');
                console.log(treeObj);
               
            }
        });

    });
    
    function save(){    
                $.ajax({
                    type:"post",
                    url:"/menu/saveMenu",
                    data: $('#saveForm').serialize(),//表单数据
                    success:function(d){
                        if(d=="success"){
                              /* layer.msg("更新成功！"); */
				    		 //当你在iframe页面关闭自身时
	 	         		    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	              			  //layer信息提示
	              		 layer.msg('保存成功');//下面是关键代码
		 	           	 setTimeout(function () { parent.layer.close(index) }, 330);//延迟
		 	              
                        }
                        if(d=="error"){
                            layer.msg('保存异常!');
                        }
                        
						setTimeout(function (){
						 
							 window.parent.location.reload();
						}, 500);
                    }
                })
    }
    
   
</script>
</html>